73. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2020-08-14 00:01:31 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

73.1 Files compared

#LocationFileLast Modified
1Porto v3.2.3/Magento 2.x/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterCategory.php2018-10-10 20:33:20 +0000
2Porto v3.2.4/Magento 2.x/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterCategory.php2020-06-26 11:11:14 +0000

73.2 Comparison summary

DescriptionBetween
Files 1 and 2
Text BlocksLines
Unchanged20296
Changed1539
Inserted46
Removed00

73.3 Comparison options

WhitespaceConsecutive whitespace is treated as a single space
Character caseDifferences in character case are significant
Line endingsDifferences in line endings (CR and LF characters) are ignored
CR/LF charactersNot shown in the comparison detail
Active line-pairing rules

73.4 Active regular expressions

No regular expressions were active.

73.5 Comparison detail

1 <?php 1 <?php
2 /** 2 /**
3  * Mageplaza 3  * Mageplaza
4  * 4  *
5  * NOTICE OF LICENSE 5  * NOTICE OF LICENSE
6  * 6  *
7  * This source file is subject to the Mageplaza.com license that is 7  * This source file is subject to the Mageplaza.com license that is
8  * available through the world-wide-web at this URL: 8  * available through the world-wide-web at this URL:
9  * https://www.mageplaza.com/LICENSE.txt 9  * https://www.mageplaza.com/LICENSE.txt
10  * 10  *
11  * DISCLAIMER 11  * DISCLAIMER
12  * 12  *
13  * Do not edit or add to this file if you wish to upgrade this extension to newer 13  * Do not edit or add to this file if you wish to upgrade this extension to newer
14  * version in the future. 14  * version in the future.
15  * 15  *
16  * @category    Mageplaza 16  * @category    Mageplaza
17  * @package     Mageplaza_LayeredNavigation 17  * @package     Mageplaza_LayeredNavigation
18  * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/) 18  * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
19  * @license     https://www.mageplaza.com/LICENSE.txt 19  * @license     https://www.mageplaza.com/LICENSE.txt
20  */ 20  */
21  21 
22 namespace Mageplaza\LayeredNavigation\Model\Layer\Filter; 22 namespace Mageplaza\LayeredNavigation\Model\Layer\Filter;
23  23 
24 use Magento\Catalog\Model\Layer as LayerCatalog; 24 use Magento\Catalog\Model\Layer as LayerCatalog;
25 use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory; 25 use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory;
26 use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; 26 use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder;
27 use Magento\Catalog\Model\Layer\Filter\ItemFactory; 27 use Magento\Catalog\Model\Layer\Filter\ItemFactory;
28 use Magento\CatalogSearch\Model\Layer\Filter\Category as AbstractFilter; 28 use Magento\CatalogSearch\Model\Layer\Filter\Category as AbstractFilter;
    29 use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection;
29 use Magento\Framework\App\RequestInterface; 30 use Magento\Framework\App\RequestInterface;
30 use Magento\Framework\Escaper; 31 use Magento\Framework\Escaper;
    32 use Magento\Framework\Exception\LocalizedException;
    33 use Magento\Framework\Exception\StateException;
31 use Magento\Store\Model\StoreManagerInterface; 34 use Magento\Store\Model\StoreManagerInterface;
32 use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper; 35 use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper;
33  36 
34 /** 37 /**
35  * Class Category 38  * Class Category
36  * @package Mageplaza\LayeredNavigation\Model\Layer\Filter 39  * @package Mageplaza\LayeredNavigation\Model\Layer\Filter
37  */ 40  */
38 class Category extends AbstractFilter 41 class Category extends AbstractFilter
39 { 42 {
40     /** @var \Mageplaza\LayeredNavigation\Helper\Data */ 43     /** @var LayerHelper */
41     protected $_moduleHelper; 44     protected $_moduleHelper;
42  45 
43     /** @var bool Is Filterable Flag */ 46     /** @var bool Is Filterable Flag */
44     protected $_isFilter = false; 47     protected $_isFilter = false;
45  48 
46     /** @var \Magento\Framework\Escaper */ 49     /** @var 
Escaper */
47     private $escaper; 50     private $escaper;
48  51 
49     /** @var  \Magento\Catalog\Model\Layer\Filter\DataProvider\Category */ 52     /** @var  LayerCatalog\Filter\DataProvider\Category */
50     private $dataProvider; 53     private $dataProvider;
51  54 
52     /** 55     /**
53      * Category constructor. 56      * Category constructor.
    57      *
54      * @param ItemFactory $filterItemFactory 58      * @param ItemFactory $filterItemFactory
55      * @param StoreManagerInterface $storeManager 59      * @param StoreManagerInterface $storeManager
56      * @param LayerCatalog $layer 60      * @param LayerCatalog $layer
57      * @param DataBuilder $itemDataBuilder 61      * @param DataBuilder $itemDataBuilder
58      * @param Escaper $escaper 62      * @param Escaper $escaper
59      * @param CategoryFactory $categoryDataProviderFactory 63      * @param CategoryFactory $dataProviderFactory
60      * @param LayerHelper $moduleHelper 64      * @param LayerHelper $moduleHelper
61      * @param array $data 65      * @param array $data
    66      *
    67      * @throws LocalizedException
62      */ 68      */
63     public function __construct( 69     public function __construct(
64         ItemFactory $filterItemFactory, 70         ItemFactory $filterItemFactory,
65         StoreManagerInterface $storeManager, 71         StoreManagerInterface $storeManager,
66         LayerCatalog $layer, 72         LayerCatalog $layer,
67         DataBuilder $itemDataBuilder, 73         DataBuilder $itemDataBuilder,
68         Escaper $escaper, 74         Escaper $escaper,
69         CategoryFactory $categoryDataProviderFactory, 75         CategoryFactory $dataProviderFactory,
70         LayerHelper $moduleHelper, 76         LayerHelper $moduleHelper,
71         array $data = [] 77         array $data = []
72     )
 78     ) {
73     {    
74         parent::__construct( 79         parent::__construct(
75             $filterItemFactory, 80             $filterItemFactory,
76             $storeManager, 81             $storeManager,
77             $layer, 82             $layer,
78             $itemDataBuilder, 83             $itemDataBuilder,
79             $escaper, 84             $escaper,
80             $categoryDataProviderFactory, 85             $dataProviderFactory,
81             $data 86             $data
82         ); 87         );
83  88 
84         $this->escaper       = $escaper; 89         $this->escaper       = $escaper;
85         $this->_moduleHelper = $moduleHelper; 90         $this->_moduleHelper = $moduleHelper;
86         $this->dataProvider  = $categoryDataProviderFactory->create(['layer' => $this->getLayer()]); 91         $this->dataProvider  = $dataProviderFactory->create(['layer' => $this->getLayer()]);
87     } 92     }
88  93 
89     /** 94     /**
90      * @inheritdoc 95      * @inheritdoc
91      */ 96      */
92     public function apply(RequestInterface $request) 97     public function apply(RequestInterface $request)
93     { 98     {
94         if (!$this->_moduleHelper->isEnabled()) { 99         if (!$this->_moduleHelper->isEnabled()) {
95             return parent::apply($request); 100             return parent::apply($request);
96         } 101         }
97  102 
98         $categoryId = $request->getParam($this->_requestVar); 103         $categoryId = $request->getParam($this->_requestVar);
99         if (empty($categoryId)) { 104         if (empty($categoryId)) {
100             return $this; 105             return $this;
101         } 106         }
102  107 
103         $categoryIds = []; 108         $categoryIds = [];
104         foreach (explode(',', $categoryId) as $key => $id) { 109         foreach (explode(',', $categoryId) as $
id) {
105             $this->dataProvider->setCategoryId($id); 110             $this->dataProvider->setCategoryId($id);
106             if ($this->dataProvider->isValid()) { 111             if ($this->dataProvider->isValid()) {
107                 $category = $this->dataProvider->getCategory(); 112                 $category = $this->dataProvider->getCategory();
108                 if ($request->getParam('id') !=
 $id) {
 113                 if ($request->getParam('id') !== $id) {
109                     $categoryIds[] = $id; 114                     $categoryIds[] = $id;
110                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id)); 115                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id));
111                 } 116                 }
112             } 117             }
113         } 118         }
114  119 
115         if (sizeof($categoryIds)) { 120         if (!empty($categoryIds)) {
116             $this->_isFilter = true; 121             $this->_isFilter = true;
117             $this->getLayer()->getProductCollection()->addLayerCategoryFilter($categoryIds); 122             $this->getLayer()->getProductCollection()->addLayerCategoryFilter($categoryIds);
118         } 123         }
119  124 
120         if ($parentCategoryId = $request->getParam('id')) { 125         if ($parentCategoryId = $request->getParam('id')) {
121             $this->dataProvider->setCategoryId($parentCategoryId); 126             $this->dataProvider->setCategoryId($parentCategoryId);
122         } 127         }
123  128 
124         return $this; 129         return $this;
125     } 130     }
126  131 
127     /** 132     /**
128      * @inheritdoc 133      * @return array
    134      * @throws StateException
129      */ 135      */
130     protected function _getItemsData() 136     protected function _getItemsData()
131     { 137     {
132         if (!$this->_moduleHelper->isEnabled()) { 138         if (!$this->_moduleHelper->isEnabled()) {
133             return parent::_getItemsData(); 139             return parent::_getItemsData();
134         } 140         }
135  141 
136         /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */ 142         /** @var 
Collection $productCollection */
137         $productCollection = $this->getLayer()->getProductCollection(); 143         $productCollection = $this->getLayer()->getProductCollection();
138  144 
139         if ($this->_isFilter) { 145         if ($this->_isFilter) {
140             $productCollection = $productCollection->getCollectionClone() 146             $productCollection = $productCollection->getCollectionClone()
141                 ->removeAttributeSearch('category_ids'); 147                 ->removeAttributeSearch('category_ids');
142         } 148         }
143  149 
144         $optionsFacetedData = $productCollection->getFacetedData('category'); 150         $optionsFacetedData = $productCollection->getFacetedData('category');
145         $category           = $this->dataProvider->getCategory(); 151         $category           = $this->dataProvider->getCategory();
146         $categories         = $category->getChildrenCategories(); 152         $categories         = $category->getChildrenCategories();
147  153 
148         $collectionSize = $productCollection->getSize(); 154         $collectionSize = $productCollection->getSize();
149  155 
150         if ($category->getIsActive()) { 156         if ($category->getIsActive()) {
151             foreach ($categories as $category) { 157             foreach ($categories as $childCategory) {
152                 $count = isset($optionsFacetedData[$category->getId()]) ? $optionsFacetedData[$category->getId()]['count'] : 0; 158                 $count = isset($optionsFacetedData[$childCategory->getId()])
153                 if ($category->getIsActive() 159                     ? $optionsFacetedData[$childCategory->getId()]['count'] : 0;
    160                 if ($childCategory->getIsActive()
154                     && $this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $collectionSize) 161                     && $this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $collectionSize)
155                 ) { 162                 ) {
156                     $this->itemDataBuilder->addItemData( 163                     $this->itemDataBuilder->addItemData(
157                         $this->escaper->escapeHtml($category->getName()), 164                         $this->escaper->escapeHtml($childCategory->getName()),
158                         $category->getId(), 165                         $childCategory->getId(),
159                         $count 166                         $count
160                     ); 167                     );
161                 } 168                 }
162             } 169             }
163         } 170         }
164  171 
165         return $this->itemDataBuilder->build(); 172         return $this->itemDataBuilder->build();
166     } 173     }
167 } 174 }